<?php
namespace YouXiMi\Controller;
use Think\Controller;
/**
 * Created by PhpStorm.
 * User: medivh
 * Date: 15-6-24
 * Time: 上午10:23
 */
Class WeChatSdkController extends Controller{
    public function sdk(){
        $options = array(
            'token'=>'youximizhijian', //填写你设定的key
        );
        $weObj = new Wechat($options);
//        $weObj->valid();//明文或兼容模式可以在接口验证通过后注释此句，但加密模式一定不能注释，否则会验证失败
        $type = $weObj->getRev()->getRevType();
        /**
         * 判断返回事件，做出相应回应
         */
        switch($type) {
            case Wechat::MSGTYPE_TEXT:
                $weObj->text("您的消息我们收到啦，请稍等哦")->reply();
                break;
            case Wechat::MSGTYPE_IMAGE:
                $weObj->text("你的图片很漂亮呢")->reply();
                break;
            case Wechat::MSGTYPE_LOCATION:
                $weObj->text("你的位置我们收到啦")->reply();
                break;
            case Wechat::MSGTYPE_LINK:
                $weObj->text("这是个什么链接呢???")->reply();
                break;
            case Wechat::MSGTYPE_EVENT:
                $EventType = $weObj->getRev()->getRevEvent();
                switch($EventType['event']){
                    case Wechat::EVENT_MENU_CLICK:
                        $weObj->text("你点击的菜单\r\n回执是".$EventType['key']."\r\n但是小游还在开发中\r\n等小游成长之后\r\n再陪你玩儿好吗\r\n请一定要等我哦")->reply();
                        break;
                    case Wechat::EVENT_SUBSCRIBE:
                        $weObj->text("感谢您的关注呢，小游在这里给您请安啦，么么哒\r\n不过呢，小游目前还没有长大\r\n据说程序员哥哥正在奋斗\r\n请等待那么点时间，程序员哥哥很快就能把我制造出来啦")->reply();
                        break;
                    case Wechat::EVENT_LOCATION:
                        $msg = $weObj->getRevData();
//                        $weObj->text("哇哦～好厉害，小游收到您的地址了呢\r\nlatitude:".$msg['Latitude']."\r\nLongitude".$msg['Longitude'])->reply();
                        break;
                    case Wechat::EVENT_SCAN:
                        $weObj->text("能来到这里也不容易，我就收下你的膝盖了")->reply();
                        break;
                    default:
                        $weObj->text("小游有点不能理解了\r\n这是key：".$EventType['key']."\r\n这是event：".$EventType['event']."\r\n偷偷的告诉你\r\n你可以把这个结果反馈给我哦")->reply();
                }
                break;
            case Wechat::MSGTYPE_MUSIC:
                $weObj->text("哇，好好听???")->reply();
                break;
            case Wechat::EVENT_SUBSCRIBE:
                $weObj->text("谢谢您的关注哦")->reply();
                break;
            case Wechat::EVENT_SCAN:
                $weObj->text("您打开了宝藏哦")->reply();
                break;
            case Wechat::EVENT_MENU_CLICK:
                $weObj->text("asd")->reply();
                break;
            default:
                $weObj->text("小游有点不能理解了，您能重新说一遍吗")->reply();
        }

    }

    /**
     * 微信菜单
     */
    public function menu(){
        $options = array(
            'appid' => 'wx1d4a09222a57113f',//填写高级调用功能的app id
 			'appsecret' => '5b165433f95f3efe6f9f0b2fefc0d582' //填写高级调用功能的密钥
        );
       $MenuData = array (
      	    'button' => array (
      	      0 => array (
      	        'name' => '游戏资讯',
      	        'sub_button' => array (
      	            0 => array (
      	              'type' => 'view',
      	              'name' => '英雄联盟',
      	              'url' => 'http://weixin.weirongm.com/YouXiMi/News/GetCode/column/1',
      	            ),
      	            1 => array (
      	              'type' => 'view',
      	              'name' => 'DOTA2',
      	              'url' => 'http://weixin.weirongm.com/YouXiMi/News/GetCode/column/2',
      	            ),
                    2 => array (
                        'type' => 'view',
                        'name' => '炉石传说',
                        'url' => 'http://weixin.weirongm.com/YouXiMi/News/GetCode/column/3',
                    ),
                    3 => array (
                        'type' => 'view',
                        'name' => '风暴英雄',
                        'url' => 'http://weixin.weirongm.com/YouXiMi/News/GetCode/column/4',
                    ),
                    4 => array (
                        'type' => 'view',
                        'name' => '星际2',
                        'url' => 'http://weixin.weirongm.com/YouXiMi/News/GetCode/column/5',
                    ),
      	        ),
      	      ),
      	      1 => array (
      	        'name' => '直播管家',
      	        'sub_button' => array (
      	            0 => array (
      	              'type' => 'click',
      	              'name' => '预约提醒',
      	              'key' => 'center_0',
      	            ),
      	            1 => array (
      	              'type' => 'view',
      	              'name' => '比赛竞猜',
      	              'url' => 'http://weixin.weirongm.com/YouXiMi/Quiz/home',
      	            )
      	        ),
      	      ),
                2 => array (
                    'name' => '游戏迷之家',
                    'sub_button' => array (
                        0 => array (
                            'type' => 'click',
                            'name' => '话题广场',
                            'key' => 'right_0',
                        ),
                        1 => array (
                            'type' => 'click',
                            'name' => '个人中心',
                            'key' => 'right_1',
                        ),
                        2 => array (
                            'type' => 'click',
                            'name' => '幸运转转转',
                            'key' => 'right_2',
                        ),
                        3 => array (
                            'type' => 'click',
                            'name' => '游戏知多少',
                            'key' => 'right_3',
                        ),
                        3 => array (
                            'type' => 'click',
                            'name' => '每日一签',
                            'key' => 'right_4',
                        )

                    ),
                ),
     	    ),
      	);
        $reslut = new Wechat($options);
        $istrue = $reslut -> createMenu($MenuData);
        echo $istrue;
    }
}